package generation;
import ec.vector.*;
import ec.*;
import ec.simple.*;
import ec.util.*;
import generation.PasswordGenerationWithMutation;

public class TransformationSimpleObjectif extends Problem implements SimpleProblemForm
{
	public void evaluate(EvolutionState state, Individual ind,
			int subpopulation, int threadnum) {

		if (ind.evaluated)
			return;

		Mutation mutation = new Mutation(PasswordGenerationWithMutationSimpleObjectif.userPassword, 
				PasswordGenerationWithMutationSimpleObjectif.availableSpace);

		IntegerVectorIndividual intVectorIndividual = (IntegerVectorIndividual) ind;
		String passwordString = mutation.applyMutation(intVectorIndividual.genotypeToStringForHumans());
		char[] password = passwordString.toCharArray();

		//evaluation of password's strength
		int nScore = PasswordStrength.getPasswordStrength(password);

		//normalization of the strength score
		float normalizeFitness = (float)(Math.abs(1 - 1/(double)(1+nScore/2)));		

		((SimpleFitness)intVectorIndividual.fitness).setFitness(state, normalizeFitness, false);
		ind.evaluated = true;

		intVectorIndividual.evaluated = true;

	}
}